package cn.com.swu.mianyangapp.ui.notifications;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.List;

import cn.com.swu.mianyangapp.R;
import cn.com.swu.mianyangapp.bean.Notice;

@SuppressLint("NotConstructor")
public class ListCardAdapter extends BaseAdapter {
    private Context mContext;
    private List<Notice> mList = new ArrayList<Notice>();

    class ViewHolder {
        TextView notice_title,publisher_id,clicks_num;
    }

    public ListCardAdapter(Context context, List<Notice> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }


    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        //初始化卡片样式
        if (view == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.notice_listcard, null);
            viewHolder.notice_title = view.findViewById(R.id.notice_title);
            viewHolder.publisher_id = view.findViewById(R.id.publisher_id);
            viewHolder.clicks_num = view.findViewById(R.id.clicks_num);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        Notice notice=mList.get(i);
        //加载卡片数据
        viewHolder.notice_title.setText(notice.getNoticeTitle());
        String str=notice.getPublisherID().toString();
        viewHolder.publisher_id.setText(str);
        viewHolder.clicks_num.setText(mList.get(i).getClicks()+"");

        return view;
    }



}
